#include <LiquidCrystal.h>
uint8_t * heapptr, * stackptr;
LiquidCrystal lcd = LiquidCrystal(3,2,9,10,11,12);
char str [] = "";
int pinSensor = 0;

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  analogReference(INTERNAL);
}
void loop(){
  /*
  if(Serial.available()){
    delay(100);
    lcd.clear();
    while(Serial.available()>0){
      lcd.write(Serial.read());
    }
  }
  */
  int suhu;
  float temp;
  suhu = analogRead(pinSensor);
  temp = 110 * (float) suhu / 1024;
  check_mem();
  lcd.clear();
  lcd.print(temp);
  lcd.print(" oC");
  lcd.setCursor(0,1);
  lcd.print(millis()/1000);
  //check_mem();
  lcd.print(";");
  lcd.print((int)heapptr,HEX);
  lcd.print(";");
  lcd.print((int)stackptr,HEX);
  lcd.write(';');
  lcd.print((int)4*1024,HEX);
  delay(1000);
}
/* This function places the current value of the heap and stack pointers in the
 * variables. You can call it from any place in your code and save the data for
 * outputting or displaying later. This allows you to check at different parts of
 * your program flow.
 * The stack pointer starts at the top of RAM and grows downwards. The heap pointer
 * starts just above the static variables etc. and grows upwards. SP should always
 * be larger than HP or you'll be in big trouble! The smaller the gap, the more
 * careful you need to be. Julian Gall 6-Feb-2009.
 */

void check_mem() {
  stackptr = (uint8_t *)malloc(4);          // use stackptr temporarily
  heapptr = stackptr;                     // save value of heap pointer
  free(stackptr);      // free up the memory again (sets stackptr to 0)
  stackptr =  (uint8_t *)(SP);           // save value of stack pointer
}

